package com.daydr3am.thenation;

import java.io.IOException;
import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.apache.http.entity.mime.MultipartEntity;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import com.coe3.data.AllIntent;
import com.coe3.data.DataStorage;
import com.coe3.data.Information;
import com.coe3.data.NewData;
import com.coe3.datahandler.BaseActivity;
import com.coe3.datahandler.HttpConnection;
import com.coe3.datahandler.ParserXMLHandler;
import com.coe3.datahandler.ParserXMLHandler.ElementData;
import com.daydr3am.lib.CustomView;
import com.daydr3am.lib.TouchyWebView;
import com.eightbitcloud.pagingscroller.Pager;

import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.core.decode.BaseImageDecoder;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.slidinglayer.SlidingLayer;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Color;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Gallery;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.RelativeLayout.LayoutParams;

@SuppressWarnings("deprecation")
public class TheNationMain extends Activity implements OnClickListener,OnTouchListener{
	
	
	AllIntent allintent=new AllIntent(TheNationMain.this);
	
	//========================Private Data=========================
	private static Boolean mIsBigScroll = true;
	private Vector<View> mListOtherViews = new Vector<View>();
	
	//========================Store=========================
	private View mViewStore = null;
	
	//========================Library=========================
	private View mViewLibrary = null;
	public static final String KEY_IS_OFFLINE = "KEY_IS_ONLINE";
	public static final String KEY_PATH_CURRENT_NEW = "KEY_PATH_CURRENT_NEW";
    
	//========================SlideMunu=========================
	private SlidingLayer mSlidingLayer;
	private String mStickContainerToRightLeftOrMiddle = "left";
	private boolean mShowShadow;
	private Button button1;
	private FrameLayout lay_my_money,lay_Morningstar,lay_Top40,lay_Video,lay_Photo;
	private RelativeLayout lay_main;
	private LinearLayout lay_slideMenu;
	private View mViewWeb = null;
	private View mViewPhoto = null;
	private View mViewVdo = null;
	
	//=========View==============
	private FrameLayout  mainView; 
//	private RelativeLayout Relay_web,Relay_photo,Relay_vdo;
	
	//========Lastest Help============
	private View mViewLastest = null;
	private View mViewHelp = null;
	
	private Pager scroller;
    boolean subclick;
    int orientation;
    static int[][] Col={{3,65,145},{59,132,62},{50,28,150},{11,132,182},{93,128,145},{156,41,49},{218,128,11},{172,3,140},{215,209,7}};
	OnTouchListener headSectionEvent=new OnTouchListener() {
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			
			setGoneOtherView();
			scroller.setVisibility(View.VISIBLE);
			
			if(event.getAction()==MotionEvent.ACTION_UP){
				Log.v("hello", "act up");
				int index=(int) (event.getX())/(v.getWidth()/9);
		        FrameLayout sectionColor = ((FrameLayout)findViewById(R.id.sectionColor));
		        sectionColor.setBackgroundColor(Color.rgb(Col[index][0], Col[index][1], Col[index][2]));

		        Pager page=(Pager) findViewById(R.id.bigscroll);
		        String[] map = getResources().getStringArray(R.array.maping);
		        for(int i=0;i<map.length;i++){
		        	Log.v("hello",index+ " "+map[i]+" "+i);
		        	if(Integer.parseInt( map[i])==index+1){
		        		if(i!=0){
		        			page.scrollToPage(i-1);
		        			Log.v("hello", "scroll here "+(i-1));
		        		}
		        		else
		        			page.scrollToPage(0);
		        			
		        		break;
		        	}
		        }
		        
			}
			return true;
		}
	};
	
	OnTouchListener footEvent=new OnTouchListener() {
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			if(event.getAction()==MotionEvent.ACTION_UP){
		        Pager page=(Pager) findViewById(R.id.bigscroll);
		        String[] map = getResources().getStringArray(R.array.maping);
				float xPosition=event.getX();
				if(xPosition>30&&xPosition<70&&page.getCurrentPage()>0){
        			page.scrollToPage(page.getCurrentPage()-1);
				}
				if(xPosition<page.getWidth()-30&&xPosition>page.getWidth()-70&&page.getCurrentPage()<map.length-1)
        			page.scrollToPage(page.getCurrentPage()+1);
					
			}
			return true;
		}
	};

	@SuppressLint("SimpleDateFormat")
	@Override
	public void onResume(){
		super.onResume();
    	Date date=new Date();
    	SimpleDateFormat format=new SimpleDateFormat("EE,MMMM dd,yyyy");
    	TextView dateShow=(TextView) findViewById(R.id.showdate);
    	dateShow.setText(format.format(date));
    	
    	//Dismiss Dialog.
        dismissDownload(this);
        dismissProgress(this);
    }
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		
		//Dismiss Dialog.
        dismissDownload(this);
        dismissProgress(this);
	}
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //Set Full Screen.
        requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
        setContentView(R.layout.activity_thenationmain);
        
//        if(!Information.isOnline(getBaseContext())){
//        	if(getPathCurrentNew(getBaseContext()) != null)
//        		if(mIsBigScroll)
//                	initialPageData();
//        } else  {
//        	if(mIsBigScroll)
//            	initialPageData();
//		}//end if
        
//        if(Information.isOnline(getBaseContext())){
//        	if(mIsBigScroll)
//            	initialPageData();
//        } else {
//			if(getIsOffline(getBaseContext()))
//				if(mIsBigScroll)
//	            	initialPageData();
//		}
        
        if(getIsOffline(getBaseContext())){
			if(mIsBigScroll)
            	initialPageData();
        } else if (Information.isOnline(getBaseContext())) {
        	if(mIsBigScroll)
            	initialPageData();
		}//end if
        
        //===================Layout SlideMenu======================
		initialSlideMenu();
		
		//============================Store=======================
		initialStore();
		
		//============================Library=======================
		initialLibrary();
		
		//===========================Lastest======================
		initialLastest();
		
		//===========================Help======================
		initialHelp();
		
		//===========================Back Next======================
		initialBtnBack();
		initialBtnNext();
		

		//allintent.ShowDialog_ad("http://www.mkyong.com/android/android-webview-example/");
		
		//allintent.ShareDG("Link", "Description", "Title", "subject");
		

	//ShowDialog_ad(TheNationMain.this, "http://www.mkyong.com/android/android-webview-example/");

	}
    

	//////////////////////////////////////////////////////////////////////////
	// Dialog
	//////////////////////////////////////////////////////////////////////////
	
	private static ProgressDialog mProgressDialog = null;
	private static ProgressDialog mDownloadDialog = null;
	
	public static ProgressDialog getInstanceProgressDialong(Activity mActivity) {
		if (mProgressDialog == null) {
			mProgressDialog = new ProgressDialog(mActivity);
			mProgressDialog.setIndeterminate(true);
			mProgressDialog.setMessage( " Please wait. " );
			mProgressDialog.setCancelable( false );
		}//end if
		
		return mProgressDialog;
	}
	
	public static void setNullInstanceProgressDialong() {
		if (mProgressDialog != null) {
			mProgressDialog = null;
		}//end if
	}
	
	public static ProgressDialog getInstanceDownloadDialog(Activity mActivity) {
		if (mDownloadDialog == null) {
			mDownloadDialog = new ProgressDialog(mActivity);
	    	mDownloadDialog.setMessage(" Downloading ... ");
	    	mDownloadDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
	    	mDownloadDialog.setCancelable(false);
	    	mDownloadDialog.setProgress(0);
	    	mDownloadDialog.setMax(100);
		}//end if
		
		return mDownloadDialog;
	}
	
	public static void setNullInstanceDownloadDialog() {
		if (mDownloadDialog != null) {
			mDownloadDialog = null;
		}//end if
	}
	
	public static void dismissProgress(Activity mActivity) {
		// You can't be too careful.
		if (getInstanceProgressDialong(mActivity) != null && getInstanceProgressDialong(mActivity).isShowing() && getInstanceProgressDialong(mActivity).getWindow() != null) {
			try {
				getInstanceProgressDialong(mActivity).dismiss();
			} catch ( IllegalArgumentException ignore ) { ; }
		}
		setNullInstanceProgressDialong();
	}
	
	public static void dismissDownload(Activity mActivity) {
		// You can't be too careful.
		if (getInstanceDownloadDialog(mActivity) != null && getInstanceDownloadDialog(mActivity).isShowing() && getInstanceDownloadDialog(mActivity).getWindow() != null) {
			try {
				getInstanceDownloadDialog(mActivity).dismiss();
			} catch ( IllegalArgumentException ignore ) { ; }
		}
		setNullInstanceDownloadDialog();
	}

	//////////////////////////////////////////////////////////////////////////
	// End Dialog
	//////////////////////////////////////////////////////////////////////////
    
    public static Boolean getIsOffline(Context context)
    {
    	return DataStorage.getBoolData(context, KEY_IS_OFFLINE, false);
    }
    
    public static void setIsOffline(Context context, Boolean online)
    {
    	DataStorage.setBoolData(context, KEY_IS_OFFLINE, online);
    }
    
    public static String getPathCurrentNew(Context context)
    {
    	Information.logDEBUG("getPathCurrentNew: " + DataStorage.getStrData(context, KEY_PATH_CURRENT_NEW, null));
    	return DataStorage.getStrData(context, KEY_PATH_CURRENT_NEW, null);
    }
    
    public static void setPathCurrentNew(Context context, String path)
    {
    	Information.logDEBUG("setPathCurrentNew: " + path);
    	DataStorage.setStrData(context, KEY_PATH_CURRENT_NEW, path);
    }
    
    public void setGoneOtherView() {
    	findViewById(R.id.material_layout).setVisibility(View.GONE);
		for (View view : mListOtherViews) {
			view.setVisibility(View.GONE);
		}//end for
	}
    
    public void setVisibilityBigScroll(int visibility) {
    	mIsBigScroll = visibility == View.VISIBLE ? true : false;
    	findViewById(R.id.store_layout).setVisibility(visibility);
	}
    
    public void initialSlideMenu() {
		lay_my_money=(FrameLayout)findViewById(R.id.lay_my_money);
		lay_Morningstar=(FrameLayout)findViewById(R.id.lay_Morningstar);
		lay_Top40=(FrameLayout)findViewById(R.id.lay_Top40);
		lay_Video=(FrameLayout)findViewById(R.id.lay_Video);
		lay_Photo=(FrameLayout)findViewById(R.id.lay_Photo);
		lay_slideMenu=(LinearLayout)findViewById(R.id.lay_slideMenu);
		
	    lay_slideMenu.setOnClickListener(this);
		//============================InitSlideMenu=================
		getPrefs();
		bindViews();
		initState();
	}
    
    public static int getPageIndex(Context context) {
    	Pager page=(Pager) ((Activity) context).findViewById(R.id.bigscroll);
		return page.getCurrentPage();
	}
    
    public void initialBtnBack() {
    	findViewById(R.id.main_btn_back).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Pager page=(Pager) findViewById(R.id.bigscroll);
				int index = page.getCurrentPage();
				if (index > 0)
					page.scrollToPage(index = index - 1);
				else
					page.scrollToPage(0);
			}
		});
	}
    
    public void initialBtnNext() {
    	findViewById(R.id.main_btn_next).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				Pager page=(Pager) findViewById(R.id.bigscroll);
				int index = page.getCurrentPage();
				int count = page.getPageCount();
				
				if (index < (count - 1))
					page.scrollToPage(index = index + 1);
				else 
					page.scrollToPage(count - 1);
			}
		});
	}
    
    public void initialStore() {
    	mViewStore = findViewById(R.id.store_layout);
    	findViewById(R.id.main_btn_store).setOnClickListener(new OnClickListener() {
				
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				setGoneOtherView();
				if(scroller != null)
					scroller.setVisibility(View.GONE);
				mViewStore.setVisibility(View.VISIBLE);
				Store.getInstance().initial(TheNationMain.this);
				addOtherView(mViewStore);
			}
		});
	}
    
    public void initialLibrary() {
    	mViewLibrary = findViewById(R.id.library_layout);
    	findViewById(R.id.main_btn_library).setOnClickListener(new OnClickListener() {
				
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				setGoneOtherView();
				if(scroller != null)
					scroller.setVisibility(View.GONE);
				mViewLibrary.setVisibility(View.VISIBLE);
				Library.getInstance().initial(TheNationMain.this);
				addOtherView(mViewLibrary);
			}
		});
	}
    
    public void initialLastest() {
    	mViewLastest = findViewById(R.id.lastest_layout);
    	findViewById(R.id.main_btn_lastest).setOnClickListener(new OnClickListener() {
				
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				setGoneOtherView();
				if(scroller != null)
					scroller.setVisibility(View.GONE);
				mViewLastest.setVisibility(View.VISIBLE);
				Lastest.getInstance().initial(TheNationMain.this);
			
				addOtherView(mViewLastest);
			}
		});
	}
    
    public void initialHelp() {
    	mViewHelp = findViewById(R.id.help_layout);
    	findViewById(R.id.main_btn_help).setOnClickListener(new OnClickListener() {
				
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				setGoneOtherView();
				if(scroller != null)
					scroller.setVisibility(View.GONE);
				mViewHelp.setVisibility(View.VISIBLE);
				Help.getInstance().initial(TheNationMain.this);
			
				addOtherView(mViewHelp);
			}
		});
	}
    
    public Boolean addOtherView(View view) {
    	if (!mListOtherViews.contains(view)) {
			mListOtherViews.add(view);
			
			for (View view2 : mListOtherViews) {
				Information.logDEBUG("addOtherView: " + view2.getClass().toString());
			}//end for
			
			return true;
		} else {
			return false;
		}//end if
	}
    
    public void initialPageData() {
    	Information.logDEBUG("### initialPageData  ###");
    	
    	mListOtherViews.removeAllElements();
    	
    	scroller = ((Pager)findViewById(R.id.bigscroll));
        HorizontalScrollView sectionMenu = ((HorizontalScrollView)findViewById(R.id.sectionScrollView));
        FrameLayout sectionColor=(FrameLayout) findViewById(R.id.sectionColor);
        mainView=(FrameLayout) findViewById(R.id.mainView);
        
        sectionColor.setBackgroundColor(Color.rgb(Col[0][0], Col[0][1], Col[0][2]));
        View view=sectionMenu.getChildAt(0); 
        view.setOnTouchListener(headSectionEvent);
        
        LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
        String[] content = null;
        String[] fullad = null;
        
//        if(Information.isOnline(getBaseContext())){
//        	content = getResources().getStringArray(R.array.url_feed);
//            fullad = getResources().getStringArray(R.array.url_fullad);
//        } else if(TheNationMain.getIsOffline(getBaseContext())){
//        	content = getResources().getStringArray(R.array.url_offline_feed);
//            fullad = getResources().getStringArray(R.array.url_offline_fullad);
//        }//end if
        
        	
    	if(TheNationMain.getIsOffline(getBaseContext())){
        	content = getResources().getStringArray(R.array.url_offline_feed);
            fullad = getResources().getStringArray(R.array.url_offline_fullad);
        } else {
        	if(Information.isOnline(getBaseContext())){
            	content = getResources().getStringArray(R.array.url_feed);
                fullad = getResources().getStringArray(R.array.url_fullad);
            }
		}//end if
        
//        String[] content = getResources().getStringArray(R.array.url_feed);
//        String[] fullad = getResources().getStringArray(R.array.url_fullad);
        
        for (int i = 0; i < content.length; i++) {
        	if(content[i].length()>5){	
        		View pageView = layoutInflater.inflate(R.layout.custommainlayout, null);
        		((CustomView) pageView).index=i;
        		
        		scroller.addPage(pageView);
        	}
        	else{
	        	TouchyWebView web=new TouchyWebView(this);
	        	
	        	if(TheNationMain.getIsOffline(getBaseContext()))
				{
					String url = "file://" + getPathCurrentNew(getBaseContext());
	        		if(getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE)
		        		web.url = url + "/FullPage-H.html";
		        	else
		        		web.url = url + "/FullPage-V.html";
				} else {
					if (Information.isOnline(getBaseContext())) {
		        		if(getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE)
			        		web.url="http://www.nationmultimedia.com/home/banner/ipad-banner/Nation/Full-Page-Nation/H"+fullad[i];
			        	else
			        		web.url="http://www.nationmultimedia.com/home/banner/ipad-banner/Nation/Full-Page-Nation/V"+fullad[i];
					}//end if
				}//end if
	        		
	        	scroller.addPage(web);
//	        	web.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
	        	web.getSettings().setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
	    	    if(i==0)
	    	    	web.onShowView();
        	}
        }
	}
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	
        getMenuInflater().inflate(R.menu.activity_thenationmain, menu);
        return true;
    }
    
    public void scrollMain(int pageIndex){
    	backToHome();
        String[] map = getResources().getStringArray(R.array.maping);
        int section=Integer.parseInt( map[pageIndex])-1;
        Log.v("hello", "section up "+section);
        if(section==-1&&pageIndex!=0)
        	section=Integer.parseInt( map[pageIndex+1])-1;
        Log.v("hello", "section color "+section);
    	FrameLayout sectionColor = ((FrameLayout)findViewById(R.id.sectionColor));
    	sectionColor.setBackgroundColor(Color.rgb(Col[section][0], Col[section][1], Col[section][2]));
    }

    public void clickNews(Node obj){
    	findViewById(R.id.bigscroll).setVisibility(View.INVISIBLE);
    	Log.v("hello", "test "+findViewById(R.id.material_layout));
    	findViewById(R.id.material_layout).setVisibility(View.VISIBLE);
    	
    	Material control=(Material) findViewById(R.id.material_control);
    	control.setObj(obj);
    }
    
    public void backToHome(){
    	findViewById(R.id.material_layout).setVisibility(View.INVISIBLE);
    	findViewById(R.id.bigscroll).setVisibility(View.VISIBLE);
    }
    
    public static int getSectionFromPage(int page,Context con){
        String[] map = con.getResources().getStringArray(R.array.maping);
        int section=Integer.parseInt( map[page])-1;
    	return section;
    }
    public static int getColor(int pageIndex,Context con){
        int section=getSectionFromPage(pageIndex,con);
        if(section==-1){
        	return Color.WHITE;
        }
        return Color.rgb(Col[section][0], Col[section][1], Col[section][2]);
    }
    
    @Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
    	if(v.getId()==R.id.lay_slideMenu)
    	{
    		if (!mSlidingLayer.isOpened()) {
				mSlidingLayer.openLayer(true);
				lay_Photo.setBackgroundResource(R.drawable.custom_button);
				lay_my_money.setBackgroundResource(R.drawable.custom_button);
				lay_Top40.setBackgroundResource(R.drawable.custom_button);
				lay_Video.setBackgroundResource(R.drawable.custom_button);
				lay_Morningstar.setBackgroundResource(R.drawable.custom_button);
			}
    	}
		
	}
    
    public boolean onKeyDown( int keyCode, KeyEvent event ) {

	    if ( keyCode == KeyEvent.KEYCODE_BACK ) {
	    	
	    	if (mSlidingLayer.isOpened())
	    	{
	    		mSlidingLayer.closeLayer(true);
	    	} else {
	    		if(scroller != null){
	    			if(scroller.getVisibility() == View.GONE){
	    				setGoneOtherView();
	    				scroller.setVisibility(View.VISIBLE);
	    			} else {
	    				clearFlag();	
	    			}//end if
	    		} else {
	    			clearFlag();
				}//end if
    		}//end if
	    	return true;
	    }

	    return super.onKeyDown(keyCode, event);
	}
    
    public void clearFlag() {
    	setIsOffline(this, false);
    	finish();
	}
    
    @Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
    	
    	Log.e("EVT", "Touch");
    	
		return false;
	}
    
    //==========================SlideMenu==================================
    private void bindViews() {
		mSlidingLayer = (SlidingLayer) findViewById(R.id.slidingLayer1);
	}
    private void CloseSlide()
	{
		if(mSlidingLayer.isOpened())
			mSlidingLayer.closeLayer(true);
	}

	/**
	 * Get current value for preferences
	 */
	private void getPrefs() {
		SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(this);
		mStickContainerToRightLeftOrMiddle = prefs.getString("layer_location",
				"left");
		mShowShadow = prefs.getBoolean("layer_has_shadow", false);
	}

	/**
	 * Initializes the origin state of the layer
	 */
	private void initState() {

		LayoutParams rlp = (LayoutParams) mSlidingLayer.getLayoutParams();
		
		mSlidingLayer.setLayoutParams(rlp);

		// Sets the shadow of the container
		if (mShowShadow) {
			mSlidingLayer.setShadowWidthRes(R.dimen.shadow_width);
			mSlidingLayer.setShadowDrawable(R.drawable.sidebar_shadow);
		} else {
			mSlidingLayer.setShadowWidth(0);
			mSlidingLayer.setShadowDrawable(null);
		}
	}
	
	public void OnclickSlideMenu(View v)
	{
		
		//custom_button
		
		Log.e("TNT", "==OnclickSlideMenu==");
			if(v.getId() ==R.id.lay_my_money)
			{
				lay_my_money.setBackgroundColor(Color.parseColor("#00bfff"));
				lay_Morningstar.setBackgroundResource(R.drawable.custom_button);
				lay_Top40.setBackgroundResource(R.drawable.custom_button);
				lay_Video.setBackgroundResource(R.drawable.custom_button);
				lay_Photo.setBackgroundResource(R.drawable.custom_button);
				CloseSlide();
				
				LoadContentSlideMenu("http://thenation.thailistedcompany.com/?device=ipad");
			}
			else if(v.getId() ==R.id.lay_Morningstar)
			{
				lay_Morningstar.setBackgroundColor(Color.parseColor("#00bfff"));
				lay_my_money.setBackgroundResource(R.drawable.custom_button);
				lay_Top40.setBackgroundResource(R.drawable.custom_button);
				lay_Video.setBackgroundResource(R.drawable.custom_button);
				lay_Photo.setBackgroundResource(R.drawable.custom_button);
				CloseSlide();
				LoadContentSlideMenu("http://www.nationmultimedia.com/home/morningstar/index1.html");
			}
			else if(v.getId() ==R.id.lay_Top40)
			{
				lay_Top40.setBackgroundColor(Color.parseColor("#00bfff"));
				lay_my_money.setBackgroundResource(R.drawable.custom_button);
				lay_Morningstar.setBackgroundResource(R.drawable.custom_button);
				lay_Video.setBackgroundResource(R.drawable.custom_button);
				lay_Photo.setBackgroundResource(R.drawable.custom_button);
				CloseSlide();
				LoadContentSlideMenu("http://www.nationmultimedia.com/top40/home/demo_ipad/");
			}
			else if(v.getId() ==R.id.lay_Video){
				
				lay_Video.setBackgroundColor(Color.parseColor("#00bfff"));
				lay_my_money.setBackgroundResource(R.drawable.custom_button);
				lay_Top40.setBackgroundResource(R.drawable.custom_button);
				lay_Morningstar.setBackgroundResource(R.drawable.custom_button);
				lay_Photo.setBackgroundResource(R.drawable.custom_button);
				CloseSlide();
				LoadContentVdo();
			}
			else if(v.getId() ==R.id.lay_Photo)
			{
				lay_Photo.setBackgroundColor(Color.parseColor("#00bfff"));
				lay_my_money.setBackgroundResource(R.drawable.custom_button);
				lay_Top40.setBackgroundResource(R.drawable.custom_button);
				lay_Video.setBackgroundResource(R.drawable.custom_button);
				lay_Morningstar.setBackgroundResource(R.drawable.custom_button);
				CloseSlide();
				LoadContentPhoto();
			}
	}
	
    //=========================WebView Mymonry Top40==========================
//	public  String URL="https://www.google.co.th";
	@SuppressLint({ "SetJavaScriptEnabled", "CutPasteId" })
	private void LoadContentSlideMenu(String url)
	{
		setGoneOtherView();
		if(scroller != null)
			scroller.setVisibility(View.GONE);
		mViewWeb = findViewById(R.id.webview_layout);
		mViewWeb.setVisibility(View.VISIBLE);
		addOtherView(mViewWeb);
		
		
		WebView webView = (WebView) findViewById(R.id.webView1);
		
		webView.getSettings().setJavaScriptEnabled(true);

		webView.loadUrl(url);
     
   
		webView.setWebChromeClient(new WebChromeClient() {
        	
        	
        	ProgressBar mProgress=(ProgressBar)findViewById(R.id.progressBar);	
            public void onProgressChanged(WebView view, int progress)
            {
				mProgress.setProgress(progress);
                Log.e("TNT",""+(progress)+"");
              if(progress==100)
              {
            	  mProgress.setVisibility(View.GONE);
              }
              else mProgress.setVisibility(View.VISIBLE);
            	  
            }

        });
 
		
		webView.loadUrl(url);
	
	}
	
	//==========================PhotoLayOut==================================
	private ArrayList<String> img_url= new ArrayList<String>();
	private ArrayList<String> str_Description= new ArrayList<String>();
	
	private Gallery gallery;
	private DisplayImageOptions options;
	private ImageGalleryAdapter  galleryAdapter=new ImageGalleryAdapter();
	private ImageLoader imageLoader = ImageLoader.getInstance();
	
	private void LoadContentPhoto()
	{
		//xxx
	
		//String url = "http://www.nationmultimedia.com/new/rss/ipad_v2/ipad_vdo.xml";
		String url="http://www.nationmultimedia.com/new/rss/ipad_v2/photo.xml";
		startConnection( url, "", HttpConnection.GET, -1, null );
		
	}
		//=======Parser=====
		@SuppressLint("HandlerLeak")
		public void startConnection( String url, String data , int method, final int handlerType, final MultipartEntity entity ) {
			Log.e("max", "MainActivity==========startConnection");
			Log.e("chud", "url: " + url);
			Log.e("chud", "data: " + data);
			
			Handler handler = new Handler() {
				public void handleMessage(Message message) {
					switch ( message.what ) {
					case HttpConnection.DID_START:
//							showDialog( DIALOG_CONNECTION_START );
						getInstanceProgressDialong(TheNationMain.this).show();
						break;
					
					case HttpConnection.DID_SUCCEED:
						try {
							Log.e("chud", "(String)message.obj: " + (String)message.obj);
							startParseXMLResponse( (String)message.obj, handlerType );
						} catch ( Exception e ) {
							Log.e( "Connection Exception", "XML Pasing Excpetion : " + e );
//			        		didFinishParsing();
			        		dismissProgress(TheNationMain.this);
						}
						
						break;
					
					case HttpConnection.DID_ERROR:
						Log.e( "Connection Error", "HTTP Connection did error : " + message.obj );
						BaseActivity.showAlertBox(getBaseContext(),  "Connection Error!!!", "Please try again." );
						dismissProgress(TheNationMain.this);
						break;
					}	
				}
			};

			HttpConnection connection = new HttpConnection(handler);
			if( entity != null )
				connection.setMultipartEntity( entity );
			connection.create(method, url, data);
		}

		public void startParseXMLResponse( String response, int handlerType ) throws SAXException, ParserConfigurationException, IOException {
			
			Log.e("max", "MainActivity==========startParseXMLResponse");
			SAXParserFactory spf = SAXParserFactory.newInstance();
			SAXParser sp = spf.newSAXParser();
			XMLReader xr = sp.getXMLReader();
			
			ParserXMLHandler parser = null;
			Handler handler = handlerInformation(handlerType);
			parser = new ParserXMLHandler( handler );
			
			StringReader sr = new StringReader(response);
			InputSource is = new InputSource(sr);
			
			xr.setContentHandler(parser);
			xr.parse(is);
		}
		
		private static Vector<NewData> mListNews = new Vector<NewData>();
		private NewData mItem = null;
		@SuppressLint("HandlerLeak")
		public Handler handlerInformation(final int handlerType) {
			
			Log.e("max", "MainActivity==========handlerInformation");
			
			Handler mHandler = new Handler() {
				public void handleMessage( Message message ) {
					ElementData data = ( ElementData )message.obj;
					switch( message.what ) {
						case ParserXMLHandler.START_DOCUMENT:
							
							mListNews.removeAllElements();
							
							break;
							
						case ParserXMLHandler.DID_START_ELEMENT:
							
							if( data.name.equalsIgnoreCase(NewData.TAG_ITEM) ) 
							{
								mItem = new NewData();
							}//end if
							
							if( data.attributes.containsKey(NewData.TAG_ENCLOSURE_URL) ) 
							{
								mItem.enclosure_url = Information.setData(data.attributes.get(NewData.TAG_ENCLOSURE_URL), Information.STR_EMPTY);
							}//end if
							
							if( data.attributes.containsKey(NewData.TAG_ENCLOSURE_TYPE) ) {
								mItem.enclosure_type = Information.setData(data.attributes.get(NewData.TAG_ENCLOSURE_TYPE), Information.STR_EMPTY);
							}//end if
							
							break;
							
						case ParserXMLHandler.DID_FINISH_ELEMENT:
							
							if( data.name.equalsIgnoreCase(NewData.TAG_TITLE) ) 
							{
								mItem.title = Information.setData(data.value, Information.STR_EMPTY);
							} 
							else if( data.name.equalsIgnoreCase(NewData.TAG_DESCRIPTION) ) 
							{
								mItem.description = Information.setData(data.value, Information.STR_EMPTY);
							}
							else if( data.name.equalsIgnoreCase(NewData.TAG_VIDEO) ) 
							{
								mItem.video = Information.setData(data.value, Information.STR_EMPTY);
							}
							else if( data.name.equalsIgnoreCase(NewData.TAG_ITEM) ) 
							{
								mListNews.add(mItem);
								mItem = null;
							}//end if
							
							break;
							
						case ParserXMLHandler.END_DOCUMENT:
							
							dismissProgress(TheNationMain.this);
							setNews(mListNews);
						    SetImageToGallery();
						    
							break;
					}
				}
			};
				
			return mHandler;
		}
		public void setNews(Vector<NewData> listNews) {
			Log.e("max", "MainActivity==========setNews(Vector<NewData> listNews)");
			for (NewData newData : listNews) {
				Information.logDEBUG("title: " + newData.title);
				Information.logDEBUG("description: " + newData.description);
				Information.logDEBUG("enclosure_url: " + newData.enclosure_url);
				Information.logDEBUG("enclosure_type: " + newData.enclosure_type);
				Information.logDEBUG("video: " + newData.video);
				
				Log.e("max","newData.description="+ newData.description);
				img_url.add(newData.enclosure_url);
				str_Description.add(newData.description);
			}
		}

		//=====Gallery=========
		public static void initImageLoader(Context context) {
		// This configuration tuning is custom. You can tune every option, you may tune some of them, 
		// or you can create default configuration by
		//  ImageLoaderConfiguration.createDefault(this);
		// method.
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
				.memoryCacheExtraOptions(480, 800) // default = device screen dimensions
		        .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 80)
		      
		       
		        .threadPoolSize(3) // default
		        .threadPriority(Thread.NORM_PRIORITY - 1) // default
		        .tasksProcessingOrder(QueueProcessingType.FIFO) // default
		        .denyCacheImageMultipleSizesInMemory()
		        .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
		        .memoryCacheSize(2 * 1024 * 1024)
		        .memoryCacheSize(13) // default
		       
		        .discCacheSize(50 * 1024 * 1024)
		        .discCacheFileCount(100)
		        .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
		        .imageDownloader(new BaseImageDownloader(context)) // default
		        .imageDecoder(new BaseImageDecoder()) // default
		        .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
		      
		        .build();
		// Initialize ImageLoader with configuration.
		ImageLoader.getInstance().init(config);
	}
		
		private void startImagePagerActivity(int position) {
			/*Intent intent = new Intent(this, ImagePagerActivity.class);
			intent.putExtra(Extra.IMAGES, imageUrls);
			intent.putExtra(Extra.IMAGE_POSITION, position);
			startActivity(intent);*/
			ShowDialog(position);
	       
			
		}

		private class ImageGalleryAdapter extends BaseAdapter {
			
			ImageView imageView;
			
			@Override
			public int getCount() {
				return img_url.size();
			}

			@Override
			public Object getItem(int position) {
				return position;
			}

			@Override
			public long getItemId(int position) {
				return position;
			}

			@Override
			public View getView(final int position, View convertView, ViewGroup parent) {
				imageView = (ImageView) convertView;
				if (imageView == null) {
					imageView = (ImageView) getLayoutInflater().inflate(R.layout.item_gallery_image, parent, false);
				}
				
				/*imageView.setOnClickListener(new OnClickListener() {
					@SuppressLint("NewApi")
					@Override
					public void onClick(View view) {

						
						
						
					}
				});*/
				
				imageLoader.displayImage(img_url.get(position), imageView, options);
				return imageView;
			}
		}
		
		private void SetImageToGallery()
		{
			setGoneOtherView();
			if(scroller != null)
				scroller.setVisibility(View.GONE);
			mViewPhoto = findViewById(R.id.photo_layout);
			mViewPhoto.setVisibility(View.VISIBLE);
			addOtherView(mViewPhoto);
			
			options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.loading)
				.showImageForEmptyUri(R.drawable.loading)
				.showImageOnFail(R.drawable.loading)
				.delayBeforeLoading(1000)  // default
				.cacheInMemory() // default
				.cacheOnDisc() // default
				.bitmapConfig(Bitmap.Config.RGB_565)
				.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
				.bitmapConfig(Bitmap.Config.ARGB_8888) // default
     
				.displayer(new SimpleBitmapDisplayer()) // default
				.handler(new Handler()) // default
				.build();
			
			initImageLoader(getApplicationContext());
			

			gallery = (Gallery) findViewById(R.id.gallery);
			gallery.setAdapter(galleryAdapter);
			gallery.setOnItemClickListener(new OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
					startImagePagerActivity(position);
					
				}
			});
			
		}
		
		 public int i_dg_photo=0;	
		 public void ShowDialog(int id)
			{
			 
			 	
			 
			 
				Log.e("max"," ShowDialog id="+ id);
				 final Dialog dialog = new Dialog(TheNationMain.this,android.R.style.Theme_Translucent_NoTitleBar);
		         dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
		         dialog.setContentView(R.layout.photo_alertdilog);
		         dialog.setCancelable(true);
		         dialog.setCanceledOnTouchOutside(false);
		         
		         FrameLayout Lay_dialog=(FrameLayout)dialog.findViewById(R.id.Lay_dialog);
		         final FrameLayout Lay_text=(FrameLayout)dialog.findViewById(R.id.Lay_text);
		         
		         

		         ImageView img_new=(ImageView)dialog.findViewById(R.id.img_new);
		         imageLoader.displayImage(img_url.get(id), img_new, options, new SimpleImageLoadingListener());
		         
		         
		         final TextView txt_Description=(TextView)dialog.findViewById(R.id.txt_Description);
		        txt_Description.setText(str_Description.get(id));
		        		
		         
		         
		         ImageView button1 = (ImageView) dialog.findViewById(R.id.btn_close);
		         button1.setOnClickListener(new OnClickListener()
		         
		         {
		             public void onClick(View v)  // OK button
		             
		             {	
		            
		                  dialog.cancel();
		                  i_dg_photo=0;
		             }
		         });
		        
		         Lay_dialog.setOnClickListener(new OnClickListener()
		         
		         {
		             public void onClick(View v)  // OK button
		             
		             {	
		            	 i_dg_photo++;
		                  if(i_dg_photo%2==0)
		                  {
		                	  Lay_text.setVisibility(View.VISIBLE);
		                  }
		                  else
		                	  Lay_text.setVisibility(View.INVISIBLE);
		                   
		             }
		         });
		            
		         
		         
		         
		         dialog.show();
			}

		    
		
		
		
	//===============================VdoLayOut============================
		private void LoadContentVdo()
		{
			String url = "http://www.nationmultimedia.com/new/rss/ipad_v2/ipad_vdo.xml";
      		startConnection_vdo( url, "", HttpConnection.GET, -1, null );
		}
		
		
		
		private ArrayList<String> img_url_vdo= new ArrayList<String>();
		private ArrayList<String> vdo_url= new ArrayList<String>();
		
		private Gallery gallery_vdo;
		private ImageView imageView1_vdo;
		private DisplayImageOptions options_vdo;
		private ImageGalleryAdapter_vdo  galleryAdapter_vdo=new ImageGalleryAdapter_vdo();
		private ImageLoader imageLoader_vdo = ImageLoader.getInstance();
		
		//===========================Parser===============================
		@SuppressLint("HandlerLeak")
		public void startConnection_vdo( String url, String data , int method, final int handlerType, final MultipartEntity entity ) {
			Log.e("max", "MainActivity==========startConnection");
			Log.e("chud", "url: " + url);
			Log.e("chud", "data: " + data);
			
			Handler handler = new Handler() {
				public void handleMessage(Message message) {
					switch ( message.what ) {
					case HttpConnection.DID_START:
							getInstanceProgressDialong(TheNationMain.this).show();
						break;
					
					case HttpConnection.DID_SUCCEED:
						try {
							Log.e("chud", "(String)message.obj: " + (String)message.obj);
							startParseXMLResponse_vdo( (String)message.obj, handlerType );
						} catch ( Exception e ) {
							Log.e( "Connection Exception", "XML Pasing Excpetion : " + e );
							dismissProgress(TheNationMain.this);
						}
						
						break;
					
					case HttpConnection.DID_ERROR:
						Log.e( "Connection Error", "HTTP Connection did error : " + message.obj );
						BaseActivity.showAlertBox(getBaseContext(),  "Connection Error!!!", "Please try again." );
						dismissProgress(TheNationMain.this);
						break;
					}	
				}
			};
			
			HttpConnection connection = new HttpConnection(handler);
			if( entity != null )
				connection.setMultipartEntity( entity );
			connection.create(method, url, data);
		}

		public void startParseXMLResponse_vdo( String response, int handlerType ) throws SAXException, ParserConfigurationException, IOException {
			
			Log.e("max", "MainActivity==========startParseXMLResponse");
			SAXParserFactory spf = SAXParserFactory.newInstance();
			SAXParser sp = spf.newSAXParser();
			XMLReader xr = sp.getXMLReader();
			
			ParserXMLHandler parser = null;
			Handler handler = handlerInformation_vdo(handlerType);
			parser = new ParserXMLHandler( handler );
			
			StringReader sr = new StringReader(response);
			InputSource is = new InputSource(sr);
			
			xr.setContentHandler(parser);
			xr.parse(is);
		}
		
		private static Vector<NewData> mListNews_vdo = new Vector<NewData>();
		private NewData mItem_vdo = null;
		@SuppressLint("HandlerLeak")
		public Handler handlerInformation_vdo(final int handlerType) {
			
			Log.e("max", "MainActivity==========handlerInformation");
			
			Handler mHandler = new Handler() {
				public void handleMessage( Message message ) {
					ElementData data = ( ElementData )message.obj;
					switch( message.what ) {
						case ParserXMLHandler.START_DOCUMENT:
							
							mListNews_vdo.removeAllElements();
							
							break;
							
						case ParserXMLHandler.DID_START_ELEMENT:
							
							if( data.name.equalsIgnoreCase(NewData.TAG_ITEM) ) 
							{
								mItem_vdo = new NewData();
							}//end if
							
							if( data.attributes.containsKey(NewData.TAG_ENCLOSURE_URL) ) 
							{
								mItem_vdo.enclosure_url = Information.setData(data.attributes.get(NewData.TAG_ENCLOSURE_URL), Information.STR_EMPTY);
							}//end if
							
							if( data.attributes.containsKey(NewData.TAG_ENCLOSURE_TYPE) ) {
								mItem_vdo.enclosure_type = Information.setData(data.attributes.get(NewData.TAG_ENCLOSURE_TYPE), Information.STR_EMPTY);
							}//end if
							
							break;
							
						case ParserXMLHandler.DID_FINISH_ELEMENT:
							
							if( data.name.equalsIgnoreCase(NewData.TAG_TITLE) ) 
							{
								mItem_vdo.title = Information.setData(data.value, Information.STR_EMPTY);
							} 
							else if( data.name.equalsIgnoreCase(NewData.TAG_DESCRIPTION) ) 
							{
								mItem_vdo.description = Information.setData(data.value, Information.STR_EMPTY);
							}
							else if( data.name.equalsIgnoreCase(NewData.TAG_VIDEO) ) 
							{
								mItem_vdo.video = Information.setData(data.value, Information.STR_EMPTY);
							}
							else if( data.name.equalsIgnoreCase(NewData.TAG_ITEM) ) 
							{
								mListNews_vdo.add(mItem_vdo);
								mItem_vdo = null;
							}//end if
							
							break;
							
						case ParserXMLHandler.END_DOCUMENT:
							
							dismissProgress(TheNationMain.this);
							
							setNews_vdo(mListNews_vdo);
						    SetImageToGallery_vdo();
							break;
					}
				}
			};
				
			return mHandler;
		}
		public void setNews_vdo(Vector<NewData> listNews) {
			Log.e("max", "MainActivity==========setNews(Vector<NewData> listNews)");
			for (NewData newData : listNews) {
				Information.logDEBUG("title: " + newData.title);
				Information.logDEBUG("description: " + newData.description);
				Information.logDEBUG("enclosure_url: " + newData.enclosure_url);
				Information.logDEBUG("enclosure_type: " + newData.enclosure_type);
				Information.logDEBUG("video: " + newData.video);
				
				Log.e("max","enclosure_url="+ newData.enclosure_url);
				img_url_vdo.add(newData.enclosure_url);
				vdo_url.add(newData.video);
				
			}
		}
		
		//===============================Gallery===============================
	    public static void initImageLoader_vdo(Context context) {
			// This configuration tuning is custom. You can tune every option, you may tune some of them, 
			// or you can create default configuration by
			//  ImageLoaderConfiguration.createDefault(this);
			// method.
			ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
					.threadPriority(Thread.NORM_PRIORITY - 2)
					.denyCacheImageMultipleSizesInMemory()
					.discCacheFileNameGenerator(new Md5FileNameGenerator())
					.tasksProcessingOrder(QueueProcessingType.LIFO)
					.enableLogging() // Not necessary in common
					.build();
			// Initialize ImageLoader with configuration.
			ImageLoader.getInstance().init(config);
		}
		
		private void startImagePagerActivity_vdo(int position) {
			
			allintent.OpenVDO(vdo_url.get(position));
		}

		private class ImageGalleryAdapter_vdo extends BaseAdapter {
			
			ImageView imageView_vdo;
			
			@Override
			public int getCount() {
				return img_url_vdo.size();
			}

			@Override
			public Object getItem(int position) {
				return position;
			}

			@Override
			public long getItemId(int position) {
				return position;
			}

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				imageView_vdo = (ImageView) convertView;
				if (imageView_vdo == null) {
					imageView_vdo = (ImageView) getLayoutInflater().inflate(R.layout.item_gallery_vdo, parent, false);
				}
				
				/*imageView.setOnClickListener(new OnClickListener() {
					@SuppressLint("NewApi")
					@Override
					public void onClick(View view) {

						imageView.setAlpha(3.0f);
						
						
					}
				});*/
				
				imageLoader_vdo.displayImage(img_url_vdo.get(position), imageView_vdo, options_vdo);
				return imageView_vdo;
			}
		}
		
		private void SetImageToGallery_vdo()
		{
			setGoneOtherView();
			if(scroller != null)
				scroller.setVisibility(View.GONE);
			mViewVdo = findViewById(R.id.vdo_layout);
			mViewVdo.setVisibility(View.VISIBLE);
			addOtherView(mViewVdo);
			
			options_vdo = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.loading)
				.showImageForEmptyUri(R.drawable.ic_empty)
				.showImageOnFail(R.drawable.ic_error)
				.cacheInMemory()
				.cacheOnDisc()
				.bitmapConfig(Bitmap.Config.RGB_565)
				.build();
			
			initImageLoader_vdo(getApplicationContext());
			

			gallery_vdo = (Gallery) findViewById(R.id.gallery_vdo);
			gallery_vdo.setAdapter(galleryAdapter_vdo);
			gallery_vdo.setOnItemClickListener(new OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
					startImagePagerActivity_vdo(position);
					
				}
			});
		}

		
		
		public static void ShowDialog_ad(final Context context, String Url)
		{

		 
			 final Dialog dialog = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar);

			

	         dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
	         dialog.setContentView(R.layout.ad_alertdilog);
	         dialog.setCancelable(true);
	         dialog.setCanceledOnTouchOutside(false);




	 		WebView webView = (WebView)dialog. findViewById(R.id.webView1);
	 		
	 		webView.getSettings().setJavaScriptEnabled(true);
	 		webView.setWebChromeClient(new WebChromeClient() {
	         	
	         	ProgressBar mProgress=(ProgressBar)((Activity) context).findViewById(R.id.progressBar);	
	             public void onProgressChanged(WebView view, int progress)
	             {
	 				mProgress.setProgress(progress);
	                 Log.e("TNT",""+(progress)+"");
	               if(progress==100)
	               {
	             	  mProgress.setVisibility(View.GONE);
	               }
	               else mProgress.setVisibility(View.VISIBLE);
	             	  
	             }

	         });
	 		
	 		webView.setWebViewClient(new WebViewClient(){

	 		    @Override
	 		    public boolean shouldOverrideUrlLoading(WebView view, String url){
	 		      view.loadUrl(url);
	 		      return true;
	 		    }
	 		});
	  
	 		webView.loadUrl(Url);

	         ImageView button1 = (ImageView) dialog.findViewById(R.id.btn_close);
	         button1.setOnClickListener(new OnClickListener()
	         {
	             public void onClick(View v)  // OK button
	             {	
	                  dialog.cancel();
	             }
	         });

 

	         

	         dialog.show();
		}
}
